package cn.richard.demo.swagger.config;

import java.util.ArrayList;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.hutool.core.collection.CollUtil;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	@Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.richard.demo.swagger.web"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
//                .useDefaultResponseMessages(false)
//                .globalResponseMessage(RequestMethod.GET, CollUtil.list(true, 
//                		new ResponseMessageBuilder()
//                        .code(500)
//                        .message("服务器发生异常")
//                        .responseModel(new ModelRef("Error"))
//                        .build(),
//		              new ResponseMessageBuilder()
//		                .code(403)
//		                .message("资源不可用")
//		                .build()
//                ))
                ;
    }
	
	private ApiInfo apiInfo() {
		return new ApiInfo("swagger测试", "swagger测试", "v1", "termsOfServiceUrl", new Contact("参考", "https://developer.ibm.com/zh/articles/j-using-swagger-in-a-spring-boot-project/", "super_he@foxmail.com"), "license", "licenseUrl", new ArrayList<VendorExtension>());
	}
}
